package com.example.condition;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Component;

/**
 * @author 段誉
 * @create 2019-02-20 10:09
 */
//判断当JdbcFactory类不存在的时候拿默认的MysqlDefaultFactory
@ConditionalOnMissingBean(value = JdbcFactory.class, ignored = MysqlDefaultFactory.class)
//判断MysqlCondition的结果为true才会使用MysqlDefaultFactory

//其他常用的几个注解
//@Conditional 依赖的条件
//@ConditionalOnBean  在某个Bean存在的条件下
//@ConditionalOnMissingBean 在某个Bean不存在的条件下
//@ConditionalOnClass  在某个Class存在的条件下
//@ConditionalOnMissingClass  在某个Class不存在的条件下

@Conditional(MysqlCondition.class)
@Component
public class MysqlDefaultFactory implements JdbcFactory {
  @Override
  public void create() {
    System.out.println("Default Mysql create...");
  }
}
